//********************payment module scripts*********************************


//common cancel functions



function cancel(url){
	var action=url;
	document.forms[0].action=action;
	document.forms[0].submit();
}

function cancelform(form,url){
	var action=url;
	var formname=form;
	document.forms[formname].action=action;
	document.forms[formname].submit();
}

//common back funcions

function Back(url){
	var action=url;
	document.forms[0].action=action;
	document.forms[0].submit();
}

function Backform(form,url){
	var action=url;
	var formname=form;
	document.forms[formname].action=action;
	document.forms[formname].submit();
}

//common disablePayees()

//Multi DDN Support script
function disablePayees(value,form) { 
  
	var val=value;
	var formname=form;
	//document.forms[formname].payeeAccount.disabled=val;
	
}


//body_paymentaccount
function newBank() {
	document.forms[0].action="bankAccount_showCreate.action";
	document.forms[0].submit();
} 

function newcc() {
	document.forms[0].action="creditCardAccount_showCreate.action";
	document.forms[0].submit();
}

//payment addcc
	//cancel('showPaymentAccounts.do')

//payment addBank
	//cancel('showPaymentAccounts.do')

//payment editbank
	//cancel('showPaymentAccounts.do')
	
//payment editcc
	//cancel('showPaymentAccounts.do')

//body recurPmt
function newRec() {
  document.forms[0].action="showRecurringAccts.action?action=create";
  document.forms[0].submit();
}

//Payments Recur Setup
	//cancel('showrecurpmts.do')
	
function newAccount() {
	document.forms[0].action="paymentReport_showAccounts.action";
	document.forms[0].submit();
}
// Scripts to populate payee account drop down.
function BnkAccount(ddn,val,text)
{
	this.ddn = ddn;
	this.id = val;
	this.text = text;
}
	//disablePayees(document.setupReccrPaymentForm.accName.value.substring(0,5)=='ccard','setupReccrPaymentForm')
	
	//populatePayeeAcct(src, dest) is left in the jsp page since it contains scriptlets within scripts
/*	
function next_Payments_Recur_Setup(billingAccountsAlert) {	
    			
	if(document.forms['reportBody']!=null){
		document.forms['reportBody'].accName.value=document.forms['setupReccrPaymentForm'].accName.value;
		document.forms['reportBody'].payee.value=document.forms['setupReccrPaymentForm'].payee.value;
		document.forms['reportBody'].payeeAccount.value=document.forms['setupReccrPaymentForm'].payeeAccount.value;
	}
	if(document.forms['reportBody']==null)
		alert(billingAccountsAlert)
	if(document.forms['reportBody']!=null)
		document.forms['reportBody'].submit();
} */

//oneTimePaymentSelAcc

	//Backform('oneTimePaymentAccountform','onetimePay.do?page=showSelectBillingAccounts')

function getDate() {
//getting the current date in mm/dd/yyyy format.
	var currentDate = new Date();
	var year=currentDate.getYear()
	if (year < 1000)
		year+=1900
	var day=currentDate.getDay()
	var month=currentDate.getMonth()+1
	if (month<10)
		month="0"+month
	var day=currentDate.getDate()
	if (day<10)
		day="0"+day
	var today = month+"/"+day+"/"+year;
	return today;
}
/*
function callPaymentAccountNameDisplay(chkBox,divID,divIDtwo,ele) {	
	var checked = chkBox.checked ;
	var divOne =  document.getElementById(divID);			
	var divTwo =  document.getElementById(divIDtwo);			
	if(checked==1){
		divTwo.style.display= 'block';
		divOne.style.display= 'block';
     	chkBox.value='on';
		 document.forms['oneTimePaymentAccountform'].payDate.readOnly=false;
		 document.forms['oneTimePaymentAccountform'].payDate.style.background = "white";
	}else{
		divOne.style.display= 'none';
		divTwo.style.display= 'none';		
		 document.forms['oneTimePaymentAccountform'].payDate.value=document.forms['oneTimePaymentAccountform'].todayDate.value;
		 document.forms['oneTimePaymentAccountform'].payDate.readOnly=true;
		 document.forms['oneTimePaymentAccountform'].payDate.style.background = "#DBDBDB";
		ele.value="";
		//popup('oneTimePaymentPopup.do','530','200','OneTimeWarning');
	}					
}	


function show(form,ele) {
	var srcElement = form.elements['newAccountType'].value;		
	var bankAccDiv =  document.getElementById('bankAccountNameDiv');			
	var bankAccDivOne =  document.getElementById('bankAccountNameDivOne');			
	var credCardAccDiv =  document.getElementById('creditAccountNameDiv');			
	var credCardAccDivOne =  document.getElementById('creditAccountNameDivOne');			
	var checkDiv =  document.getElementById('check');			
	var ccardDiv =  document.getElementById('ccard');	
	form.elements["isSave"].checked=0;
	bankAccDiv.style.display= 'none';	
	bankAccDivOne.style.display= 'none';	
	form.elements["isCreditCardSave"].checked=0;
	credCardAccDiv.style.display= 'none';	
	credCardAccDivOne.style.display= 'none';	
	if(srcElement != '-1') {
		//var today = getDate();
		 document.getElementById("popup").style.display="none";
		 document.forms['oneTimePaymentAccountform'].payDate.value=document.forms['oneTimePaymentAccountform'].todayDate.value;
		 document.forms['oneTimePaymentAccountform'].payDate.readOnly=true;
		 document.forms['oneTimePaymentAccountform'].payDate.style.background = "#DBDBDB"
		//popup('oneTimePaymentPopup.do','530','200','OneTimeWarning');
	}
    if(srcElement == 'check') 
	{
       document.getElementById("popup").style.display="block";
       checkDiv.style.display= 'block';
	   ccardDiv.style.display='none';		
	   document.forms['oneTimePaymentAccountform'].payeeAccount.disabled=false;
    }
	if(srcElement=='ccard')
	{		
	   document.getElementById("popup").style.display="block";
       ccardDiv.style.display='block';			   
       checkDiv.style.display='none';			   
	   document.forms['oneTimePaymentAccountform'].payeeAccount.disabled=true;
    }
	if(srcElement=='-1')
	{
		document.getElementById("popup").style.display="none";
	   ccardDiv.style.display='none';			   
	   checkDiv.style.display='none';			   
	  document.forms['oneTimePaymentAccountform'].payDate.readOnly=false;
	  document.forms['oneTimePaymentAccountform'].payDate.style.background = "white"
	   document.forms['oneTimePaymentAccountform'].payeeAccount.disabled=false;
	}
    return false;
}
*/
function showSavedAccnt(form,ele) {		    
	var srcElement = form.elements['paymentSource'].value;				
	if(srcElement=='-1')
	{
		savedAccount.style.display='none';
	}else {				
		savedAccount.style.display='block';			   
	}			
    return false;
}

/*
function forceSelect(form,value){
	document.getElementById("popup").style.display="none";
	document.forms['oneTimePaymentAccountform'].payDate.readOnly=false;
	document.forms['oneTimePaymentAccountform'].payDate.style.background = "white"
	document.forms['oneTimePaymentAccountform'].payeeAccount.disabled=false;
	var checkDiv =  document.getElementById('check');			
	var ccardDiv =  document.getElementById('ccard');	
	if(value=="existing")
	{
		selectCtl = form.elements["paymentSource"];
		selectCtl.disabled=false;			
		selectCtl = form.elements["newAccountType"];
		selectCtl.value="-1";
		selectCtl.disabled=true;
		checkDiv.style.display= 'none';
		ccardDiv.style.display='none';
	}
	if(value=="createNewAccount")
	{
		//savedAccount.style.display='none';
		selectCtl = form.elements["newAccountType"];
		selectCtl.disabled=false;
		selectCtl = form.elements["paymentSource"];
		selectCtl.value="-1";
		selectCtl.disabled=true;
		selectCtl = document.forms['oneTimePaymentAccountform'].elements["newAccountType"];
		if(selectCtl.value!=null)
		{
			if(selectCtl.value=='check')
			{
	   			checkDiv.style.display= 'block';
  			    ccardDiv.style.display='none';		
			}
			if(selectCtl.value=='ccard')
			{
			   ccardDiv.style.display='block';			   
			   checkDiv.style.display='none';			   
			}
			if(selectCtl.value=='-1')
			{
			   ccardDiv.style.display='none';			   
			   checkDiv.style.display='none';			   
			}
		}
	}
}
*/
function disableRadioButton()
{  
  if(document.getElementById("check") != null) {  /*  this condition was added to work only with onetiimepaymentSelAcc */ 
	
      radioCtl = document.forms['oneTimePaymentAccountform'].elements["paymentAccountStatus"];	
	selectCtl = document.forms['oneTimePaymentAccountform'].elements["newAccountType"];	
	selectCtl2 = document.forms['oneTimePaymentAccountform'].elements["paymentSource"];				
	var checkDiv =  document.getElementById('check');			
	var ccardDiv =  document.getElementById('ccard');	
	var radioButtonValue = null;
	if(radioCtl[0].checked) {
		radioButtonValue=radioCtl[0].value;
	}else {
		radioButtonValue=radioCtl[1].value;	
	}
	if(radioButtonValue=='createNewAccount')
	{	
		var temp = selectCtl.value;
		if(temp=="check" || temp=="ccard")
		{
			if(selectCtl.value=='check')
			{  
			   checkDiv.style.display= 'block';
			   ccardDiv.style.display='none';	
			}
			if(selectCtl.value=='ccard')
			{
			   ccardDiv.style.display='block';			   
			   checkDiv.style.display='none';			   
			}
			selectCtl.disabled=false;
			selectCtl2.disabled=true;
			var isSaveValue = document.forms['oneTimePaymentAccountform'].isSave.value;
			var isCredValue = document.forms['oneTimePaymentAccountform'].isCreditCardSave.value;
			if( (isSaveValue=='on' && isCredValue=='') || (isSaveValue=='' && isCredValue=='on') || (isSaveValue=='on' && isCredValue=='on') ) {
				document.forms['oneTimePaymentAccountform'].isSave.checked=true;
				document.forms['oneTimePaymentAccountform'].isCreditCardSave.checked=true;
				document.forms['oneTimePaymentAccountform'].payDate.readOnly=false;			
				document.forms['oneTimePaymentAccountform'].payDate.style.background = "white";
			} else {
				document.forms['oneTimePaymentAccountform'].isSave.checked=false;
				document.forms['oneTimePaymentAccountform'].isCreditCardSave.checked=false;
				document.forms['oneTimePaymentAccountform'].payDate.value=getDate();
				document.forms['oneTimePaymentAccountform'].payDate.readOnly=true;		
				document.forms['oneTimePaymentAccountform'].payDate.style.background = "#DBDBDB";
			}
	  	}
	}else if(selectCtl.value=='-1' && radioButtonValue=='existing' ) {					   
		   selectCtl.disabled=true;
		   selectCtl2.disabled=false;
		   ccardDiv.style.display='none';			   
		   checkDiv.style.display='none';
		   radioCtl[0].checked=true;
	}	
	temp="";
	if(selectCtl2.value!=-1){
	temp = selectCtl2.value.substring(0,5);
	}
	if(temp=="check" || temp=="ccard")
	{
	    selectCtl.disabled=true;
	   selectCtl2.disabled=false;				  	   		   
	}else if(selectCtl2.value=='-1' && radioButtonValue=='createNewAccount') {
	   selectCtl.disabled=false;
	   selectCtl2.disabled=true;
	   radioCtl[1].checked=true;
	}
  }
} 

	//cancelform('oneTimePaymentAccountform','onetimePay.do?rptAction=keepValue&transformerId=tr1&columnId=checkbox&value=true')
	//disablePayees(document.oneTimePaymentAccountform.paymentSource.value.substring(0,5)=='ccard','oneTimePaymentAccountform')
	//BnkAccount(ddn,val,text)
	//populatePayeeAcct(src, dest) is left in the jsp page since it contains scriptlets within scripts

function next_oneTimePaymentSelAcc(){				
	document.forms['oneTimePaymentAccountform'].submit();
	document.forms['oneTimePaymentAccountform'].submits.disabled=true;
}


//cancelOneTimePayment
	//cancelform('cancelForm','./showPaymentActivity.do')
function submit() {
	document.forms['cancelForm'].action="./cancelOneTimePayment.do";
	document.forms['cancelForm'].submit();
}

//onetimeCancelConfirmation
	//Back('./showPaymentActivity.do')

//editOneTimePaymentRec
	//cancelform('oneTimePaymentAccountform','./showPaymentActivity.do')

//confirmEditOneTimePaymentRec
	//cancelform('oneTimePaymentAccountform','./showPaymentActivity.do') 

//header payment
function fnPopup(url)
{
	var x="600";
	var y="550";
	popup(url,x,y);
}
	
	
//payment confirmbankacc
	//cancel('showPaymentAccounts.do')

//payment confirmcreditcardacc
	//cancel('showPaymentAccounts.do')

//Payments Recur Options
	//cancel('showrecuracts.do')
	
function disableElement(element,val) { 
    document.getElementById(element).disabled=val;
}

//Payments Recur Edit Summary
	//cancel('showrecurpmts.do')
	
//confirmEditOneTimePayment
	//cancelform('oneTimePaymentAccountform','showPaymentActivity.do')
//function submitCon() {
//	form = document.forms['oneTimePaymentAccountform'];
//	form.submit();
//}

//confirmOneTimePayment
	//cancelform('oneTimePaymentAccountform','onetimePay.do')
	//submitCon()

//dueAmountWarning
	//Backform('dueamountWarningPage','onetimePay.do?page=showSelectBillingAccounts')

//editDueAmountWarning
	//Backform('dueamountEditWarningPage','editOneTimePaymentPage.do')

//onetimeUpdateConfirmation
	//Back('./showPaymentActivity.do')
	
//Payment RecurCancel
	//cancel('showrecurpmts.do')
	
//Payments Recur Confirm
	//cancel('showrecurpmts.do')

//recurringPaymentWarning
	//Backform('OneTimePaymentWarningPage','onetimePay.do')

//Payments Recur Due Edit
	//cancel('showrecurpmts.do')
	//disablePayees(document.recurringPaymentform.paymentAccount.value.substring(0,5)=='ccard','recurringPaymentform')
	//disableElement(element,val)
	
function enableElement(element,val) { 
    document.getElementById(element).disabled =val;
}//no function calls to this function in the jsp page - not tested

function enableRadioButton()
 {
   selectCtl = document.forms['recurringPaymentform'].elements["transferDate"];
   selectCtl.enabled=true;
 }//no function calls to this function in the jsp page - not teted

function callSubmit() {
	document.forms[0].action="confirmEditRecurpmts.action?action=confirm";
	//if (document.forms[0].payeeAccount.disabled == false) {
	//	var selIndex = document.forms[0].payeeAccount.selectedIndex;
	//    document.forms[0].payeeAccountName.value=document.forms[0].elements["payeeAccount"].options[selIndex].text;
	//}
	document.forms[0].submit();
}
function createPaymentAccount() {
	document.forms[0].action="paymentReport_showAccounts.action";
	document.forms[0].submit();
}
	//BnkAccount(ddn,val,text)
	//populatePayeeAcct(src, dest) is left in the jsp page since it contains scriptlets within scripts
